package com.ml.doctor.utils;

import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * Created by gzq on 2017/11/29.
 */

public class TimeFormatter implements IAxisValueFormatter {
    private ArrayList<Long> times;

    public TimeFormatter(ArrayList<Long> times) {
        this.times = times;
    }

    @Override
    public String getFormattedValue(float v, AxisBase axisBase) {
        if (v == -1) {
            return "";
        }
        if (times.size() == 1) {
            return stampToData(times.get(0));
        }
        if (v > times.size()) {
            return "";
        }
        return stampToData(times.get((int) v));
    }

    private String stampToData(long time) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(time));
    }
}
